package jsu.xxy.coffee3.controller;

import io.swagger.v3.oas.annotations.Operation;
import jsu.xxy.coffee3.domain.MiniOrder;
import jsu.xxy.coffee3.domain.Order;
import jsu.xxy.coffee3.domain.Ordertable;
import jsu.xxy.coffee3.mapper.OrdertableMapper;
import jsu.xxy.coffee3.service.OrdertableService;
import jsu.xxy.coffee3.service.impl.OrderformServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@CrossOrigin
public class OrderController {
    @Autowired
    OrdertableService ordertableService;
    @Autowired
    OrdertableMapper orderMapper;

    /*    @RequestMapping("testO1")
        public List<Order> testO1(){
            //调用mapper层的方法
            return orderService.findAllOrderByName("amy");
        }*/


    @RequestMapping("commit")
    @Operation(summary = "订单的评论传给我用户名-userName，订单号-orderId，商品id-drinkId ，评论，评分")
    public void commit(String userName , int orderId , int drinkId,String comment , double score){

    }
    //查询用户所有订单详细信息
    @RequestMapping("findAllOrderByName")
    public List<Order> findAllOrderByName(String userName)
    {
        return ordertableService.findAllOrderByName(userName);
    }

    //查询用户今日订单缩略信息
    @RequestMapping("findTodayMiniOrder")
    public List<MiniOrder> findTodayMiniOrder(String userName)
    {
        return ordertableService.findTodayMiniOrder(userName);
    }
    //查询用户所有订单缩略信息
    @RequestMapping("findAllMiniOrder")
    public List<MiniOrder> findAllMiniOrder(String userName)
    {
        return ordertableService.findAllMiniOrder(userName);
    }

    //查询一个订单的详细信息
    @RequestMapping("findOneOrder")
    public Order findOneOrder(String userName,int orderId)
    {
        return ordertableService.findOneOrder(userName,orderId);
    }

    //////////test
    //查询用户所有订单
    @RequestMapping("test")
    public int test()
    {
        return ordertableService.test();
//        Timestamp time=new Timestamp(System.currentTimeMillis()); ;

    }

    //增加一个订单条目
    @RequestMapping("addOneOrder")
    public boolean addOneOrder(Order order)
    {
        return ordertableService.addOneOrder(order);
    }

    //增加一个订单条目
    @RequestMapping("addOneOrderByStr")
    public boolean addOneOrderByStr(String userName,String drinkStr)
    {

        return ordertableService.addOneOrderByStr(userName,drinkStr);
    }
//    @RequestMapping("testDate")
//    public static String testDate(String oldDateStr) {
//        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
//        Date date = df.parse(oldDateStr);
//        SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
//        Date date1 =  df1.parse(date.toString());
//        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        return df2.format(date1);
//    }
}
